{extend name="default/template/base_index" /}

{block name="area_header"}
{/block}

{block name="area_body"}
{include file="default/Widget/topbar" /}
<div class="admin-main container-fluid">
  {include file="default/Widget/left" /}
  <div class="admin-main-content">
    {include file="default/Widget/breadcrumb" /}
    <div class="table-responsive well">
      <h2>题目添加</h2>
      <!-- 过滤\查询按钮 -->
      <div class="filter-controls">
        <form action="{:url('Bookunit/question',['parent'=>$parent])}" class="memberForm form-inline" method="get">
          <input type="hidden" name="id" value="{$id}" />
          <input type="hidden" name="book_parent" value="{$book_parent}" />
          <input type="hidden" name="pid" value="{$pid}" />
          <div class="form-group">
            <label class="control-label">标识</label>
            <div class="input-group">
              <input class="form-control" type="text" name="kword" placeholder="标识" value="{$kword|default=''}"/>
            </div>
          </div>

          <div class="form-group">
            <label class="control-label"></label>
            <div class="input-group">
              <select class="form-control" name="dt_type" id="js-dt-type"/>
              <option value="0">== 类型 ==</option>
              {volist name="dt_types" id="v"}
              <option value="{$v.id}"  {eq name="v['id']" value="$dt_type"}selected{/eq} >{$v.name}</option>
              {/volist}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label"></label>
            <div class="input-group">
              <select class="form-control" name="all" id="js-all"/>
              <option value=""> == 范围 == </option>
              <option value="0">自己</option>
              <option value="1">全部</option>
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label">&nbsp;</label>
            <div class="input-group">
              <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>查询</button>
            </div>
          </div>
        </form>
      </div>
      <!-- 操作按钮 -->
      <div class="btn-controls">
        <a href="{:url('bookunit/edquestion',['id'=>$id,'book_parent'=>$book_parent,'pid'=>$pid])}" class="btn btn-default btn-sm"><i class="fa fa-reply"></i>返回</a>
        <a class="btn btn-sm btn-primary ajax" onclick="add()" ><i class="fa fa-plus"></i>添加选中</a>
      </div>

      <table class="table table-striped table table-hover  table-condensed">
        <thead>
        <tr>
          <th>ID</th>
          <th>标识</th>
          <th>类型</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {empty name="list"}
        <tr>
          <td colspan="5" class="text-center">{:L('NO_DATA')}</td>
        </tr>
        {else/}
        {volist name="list"  id="vo"}
        <form class="select_{$vo.id}">
          <input type="hidden" name="question_id" value="{$vo['id']}" />
          <input type="hidden" name="unit_id" value="{$id}" />
          <input type="hidden" name="book_parent" value="{$book_parent}" />
          <input type="hidden" name="pid" value="{$pid}" />
          <tr>

            <td data-id="{$vo['id']}">
              <input type="checkbox" value="{$vo.id}" name="ids[]" class="selectitem ids"/>
              <a href="{:url('Bookunit/question',['parent'=>$vo['id'],'id'=>$id,'book_parent'=>$book_parent,'pid'=>$pid,'dt_type'=>$dt_type])}">{$vo['id']}</a></td>
            <td>
              {$vo['note']|default=''}</td>
            <td>
              {:$dt_types[$vo['dt_type']]['name']}</td>
            <td>
              {if condition="$vo['status'] eq 0"}起草
              {elseif condition="$vo['status'] eq 1" /}发布
              {else /}未知{/if}</td>
        </form>
        <td>
          <a target-form="select_{$vo.id}" class="ajax-post btn btn-primary btn-sm" href="{:url('Bookunit/question')}"><i class="fa fa-save"></i>{:L('BTN_ADD')}</a>

        </td>
        </tr>

        {/volist}
        {/empty}
        </tbody>
      </table>
      <div>{$show}</div>
    </div>
  </div>
  <!-- END admin-main-content -->
</div>
<!-- END admin-main-->
{/block}

{block name="area_footer"}
<script>
  $(function(){
    $('#js-all').val(parseInt({$all}));
  });
    function add() {

      var unit_id = "{$id}";
      var chk_value = [];
      $('.ids:checked').each(function () {
        chk_value.push($(this).val());
      });
    console.log(chk_value);
      $.ajax({
        type: "POST",
        url: "{:url('Bookunit/addquestion')}",
        data: {
          ids: chk_value,
          unit_id: unit_id
        },
        context: window,
        dataType: "json",

        success: function (data) {
          $.scojs_message('添加成功', $.scojs_message.TYPE_OK);
        }
      })
    }

</script>
{/block}